local sk__shajue = fk.CreateSkill {

  name = "sk__shajue",

  tags = {},

}



sk__shajue:addEffect("active", {
  name = "sk__shajue",
  anim_type = "offensive",
  prompt = "#sk__shajue",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(sk__shajue.name, Player.HistoryPhase) == 0
  end,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= player
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local cards = table.simpleClone(player:getCardIds("h"))
    room:loseHp(player, 1, sk__shajue.name)
    local slash_names = {}
    for _, card in ipairs(Fk.cards) do
      if not table.contains(room.disabled_packs, card.package.name) and not card.is_derived and card.trueName == "slash" then
        table.insertIfNeed(slash_names, card.name)
      end
    end
    math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 6)))
    while not player.dead do
      cards = table.filter(cards, function(id)
        return table.contains(player:getCardIds("h"), id)
      end)
      if #cards == 0 or target.dead then return end
      room:delay(800)
      if not room:useVirtualCard(table.random(slash_names), table.random(cards, 1), player, target, sk__shajue.name, true) then
        break
      end
    end
  end,
})

sk__shajue:addEffect(fk.TargetSpecified, {
  can_refresh = function(self, event, target, player, data)
    return target == player and table.contains(data.card.skillNames, "sk__shajue")
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local to = data.to
    local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
    if use_event == nil then return end
    room:addPlayerMark(to, MarkEnum.MarkArmorNullified)
    use_event:addCleaner(function()
      room:removePlayerMark(to, MarkEnum.MarkArmorNullified)
    end)
  end,
})

return sk__shajue
